home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / project4 / form4.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-07-19  |  2.8 KB  |  109 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Factors"
  5.    ClientHeight    =   3690
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   4650
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   3690
  13.    ScaleWidth      =   4650
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.TextBox Text1 
  16.       Height          =   285
  17.       Left            =   120
  18.       TabIndex        =   3
  19.       Text            =   "Primes"
  20.       Top             =   2520
  21.       Width           =   4455
  22.    End
  23.    Begin VB.CommandButton Command2 
  24.       Caption         =   "Exit"
  25.       Height          =   615
  26.       Left            =   2400
  27.       TabIndex        =   2
  28.       Top             =   2880
  29.       Width           =   2175
  30.    End
  31.    Begin VB.CommandButton Command1 
  32.       Caption         =   "Calculate"
  33.       Height          =   615
  34.       Left            =   120
  35.       TabIndex        =   1
  36.       Top             =   2880
  37.       Width           =   2175
  38.    End
  39.    Begin VB.ListBox List1 
  40.       Height          =   2205
  41.       Left            =   120
  42.       TabIndex        =   0
  43.       Top             =   120
  44.       Width           =   4455
  45.    End
  46. Attribute VB_Name = "Form1"
  47. Attribute VB_GlobalNameSpace = False
  48. Attribute VB_Creatable = False
  49. Attribute VB_PredeclaredId = True
  50. Attribute VB_Exposed = False
  51. Private Sub Command1_Click()
  52.  Command1.Caption = "Recalculate"
  53.  List1.Clear
  54.  For l = 1 To 10
  55.     List1.AddItem ""
  56.  Next
  57.  List1.AddItem " 2 = (prime)"
  58.  n = 1
  59.  z = 2
  60.     y = DoEvents() ' releases time slice
  61.     z = z + 1
  62.     p = z
  63.     f = 0
  64.     S$ = Str$(p) + " = "
  65.     ' factor test number
  66.     For l = 2 To p
  67.        Do
  68.           If p / l = p \ l Then
  69.              p = p / l
  70.              If l < z Then
  71.                 If f = 0 Then
  72.                    S$ = S$ + Str$(l)
  73.                 Else
  74.                    S$ = S$ + " * " + Str$(l)
  75.                 End If
  76.              End If
  77.              f = f + 1
  78.           Else
  79.              Exit Do
  80.           End If
  81.        Loop
  82.        ' check no factors and divisor
  83.        ' greater than square of test number
  84.        If f = 0 And l > Int(Sqr(p)) Then
  85.           f = 1
  86.           Exit For
  87.        End If
  88.        ' check test number completely divided
  89.        If p = 1 Then
  90.           Exit For
  91.        End If
  92.     Next
  93.     ' check only one factor (itself)
  94.     If f = 1 Then
  95.        S$ = S$ + " (prime)"
  96.        n = n + 1
  97.        Text1.Text = "Prime numbers:" + Str$(n)
  98.     End If
  99.     ' scrolls & adds last calculation
  100.     List1.RemoveItem 0
  101.     List1.AddItem S$
  102.  Loop
  103. End Sub
  104. Private Sub Command2_Click()
  105. End Sub
  106. Private Sub Form_Load()
  107.  Beep
  108. End Sub
  109.